<template>
  <div>
    <!--    搜索表单-->

    <div >
      <el-input style="width: 100px" placeholder="请输入书名" v-model="params.name"></el-input>
      <el-input style="width: 100px; margin-left: 5px" placeholder="请输入作者" v-model="params.author"></el-input>
      <el-button style="margin-left: 5px" type="primary" @click="load()">
        <i class="el-icon-search"></i> 搜索
      </el-button>
      <el-select v-model="params.category" placeholder="请选择分类" style="width: 150px">
        <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <!--表单内容-->
    <el-table :data="tableData" stripe row-key="id" default-expand-all @selection-change="handleSelectionChange" >
      <el-table-column prop="name" label="活动名称"></el-table-column>
      <el-table-column prop="cover" label="封面" width="80">
        <template v-slot="scope">
          <el-image :src="scope.row.cover" :preview-src-list="[scope.row.cover]"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="description" label="简介" width="200" ></el-table-column>
      <el-table-column prop="author" label="作者"></el-table-column>


      <!--操作-->
      <el-table-column
          fixed="right"
          label="操作"
          width="70">
        <template v-slot="scope">
          <el-button @click="handleEdit(scope.row)" type="success" size="mini">详情<i class="el-icon-edit"></i>
          </el-button>
        </template>
      </el-table-column>


    </el-table>


    <!--    分页-->
    <div style="text-align: center; bottom: 0">
      <el-pagination
          background
          :current-page="params.pageNum"
          :page-size="params.pageSize"
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :total="total">
      </el-pagination>
    </div>

    <el-dialog title="用户信息" :visible.sync="updateTab" width="100%" top="10%">
      <el-form label-width="80px" style="" :model="updateForm" disabled :rules="rules" ref="rulerForm">

        <el-form-item label="书名" prop="name">
          <el-input v-model="updateForm.name" auto-complete="off" placeholder="请输入书名"></el-input>
        </el-form-item>
        <el-form-item label="封面" prop="cover">
          <template v-slot="scope">
            <el-image :src="scope.row.cover" :preview-src-list="[scope.row.cover]"></el-image>
          </template>
        </el-form-item>
        <el-form-item label="简介" prop="description">
          <el-input v-model="updateForm.description" auto-complete="off" placeholder="请输入简介"></el-input>
        </el-form-item>
        <el-form-item label="出版日期" prop="publishDate">
          <el-date-picker
              v-model="updateForm.publishDate"
              type="date"
              value-format="yyyy-MM-dd"
              style="width: 100%"
              placeholder="选择出版日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="作者" prop="author">
          <el-input v-model="updateForm.author" auto-complete="off" placeholder="请输入作者"></el-input>
        </el-form-item>
        <el-form-item label="出版社" prop="publisher">
          <el-input v-model="updateForm.publisher" auto-complete="off" placeholder="请输入出版社"></el-input>
        </el-form-item>
        <el-form-item label="类别" prop="category">
          <el-input v-model="updateForm.category"></el-input>

        </el-form-item>
        <el-form-item label="书号" prop="isbn">
          <el-input v-model="updateForm.isbn" auto-complete="off" placeholder="请输入书号"></el-input>
        </el-form-item>
        <el-form-item label="所需书币" prop="score">
          <el-input v-model="updateForm.score" auto-complete="off" placeholder="请输入所需书币"></el-input>
        </el-form-item>
        <el-form-item label="数量" prop="counts">
          <el-input v-model="updateForm.counts" auto-complete="off" placeholder="请输入剩余数量"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancelUpdate">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import request from "@/utils/request";
import Cookies from "js-cookie";

export default {
  name: "Category.vue",

  data() {

    return {
      user: Cookies.get('user') ? JSON.parse(Cookies.get('user')) : {},
      tableData: [],
      categories: [],
      multipleSelection: [],
      total: 0,
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      value: '',
      dialogFormVisible: false,
      updateTab: false,
      form: {},
      updateForm: {},
      options: [{
        value: '',
        label: '全部分类'
      }, {
        value: '教育',
        label: '教育'
      }, {
        value: '汉语言文学',
        label: '汉语言文学'
      }, {
        value: '计算机',
        label: '计算机'
      }, {
        value: '小说',
        label: '小说'
      }, {
        value: '传记',
        label: '传记'
      }, {
        value: '漫画',
        label: '漫画'
      }],
    }
  },


  created() {
    this.load();
    request.get('/category/tree').then(res => {
      this.categories = res.data
    })
  },


  methods: {
    handleChange() {
    },


    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    load() {
      request.get('/book/page', {
        params: this.params
      }).then(res => {
        if (res.code === '200') {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      })
    },

    reset() {
      this.params = {
        pageNum: 1,
        pageSize: 10,
      }
      this.load()
    },

    handleCurrentChange(pageNum) {
      this.params.pageNum = pageNum
      this.load()
    },




    handleEdit(row) {
      this.updateForm = row;
      this.updateTab = true;
    },

    handleCancelUpdate() {
      this.updateTab = false
      this.load()
    },


  }
}
</script>

<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.el-input /deep/ .el-input__inner{
  color: rgb(83,80,80) !important;
  cursor: pointer;

}
</style>